package com.kye.express.business.home.productintroduction;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;

import com.fondesa.recyclerviewdivider.RecyclerViewDivider;
import com.kye.express.R;
import com.kye.express.business.base.BaseToolbarActivity;
import com.kye.express.config.KyeResAction;
import com.kye.express.databinding.RecyclerviewLayoutBinding;
import com.kye.express.utils.ResourceUtils;
import com.kye.express.utils.ScreenUtils;
import com.kye.model.bean.IncrementServiceModel;

import me.drakeet.multitype.Items;
import me.drakeet.multitype.MultiTypeAdapter;

/**
 * 增值服务
 */
public class IncrementServiceActivity extends BaseToolbarActivity {
    private RecyclerviewLayoutBinding mBinding;
    private Context mContext;
    protected MultiTypeAdapter mAdapter;
    protected Items mDatas = new Items();

    public static void startActivity(Context context) {
        Intent intent = new Intent(context, IncrementServiceActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.recyclerview_layout);
        mContext = this;
        setUpToolbar((Toolbar) findViewById(R.id.toolbar));
        setTitle(getString(R.string.prod_today_add_service));
        initView();
        initDatas();
    }

    private void initView() {
        mAdapter = new MultiTypeAdapter();
        mAdapter.register(IncrementServiceModel.class, new IncrementServiceItemViewBinder(this));
        mBinding.rvData.setLayoutManager(new LinearLayoutManager(this));
        RecyclerViewDivider.with(this)
                .color(getResources().getColor(R.color.grey))
                .size(ScreenUtils.dp2px(this, 1))
                .hideLastDivider()
                .build()
                .addTo(mBinding.rvData);
        mBinding.rvData.setItemAnimator(new DefaultItemAnimator());
        mAdapter.setItems(mDatas);
        mBinding.rvData.setAdapter(mAdapter);
    }

    private void initDatas() {
        String[] titles = getResources().getStringArray(R.array.prod_increment_list);
        int[] icons = ResourceUtils.getResouceByArray(IncrementServiceActivity.this, R.array.prod_increment_icon_list);

        String[] urls = new String[]{KyeResAction.Value_insuredKey, KyeResAction.InformKey,
                KyeResAction.Storage_costsKey, KyeResAction.Msg_messageKey, KyeResAction.TokeenKey, KyeResAction.ReceiptKey,
                KyeResAction.WaterproofKey, KyeResAction.DelegationKey, KyeResAction.ReceivablesKey,
                KyeResAction.PaymentKey, KyeResAction.Gps_positionKey};

        for (int i = 0; i < titles.length; i++) {
            IncrementServiceModel incrementServiceModel = new IncrementServiceModel(icons[i], titles[i], urls[i]);
            mDatas.add(incrementServiceModel);
        }
        mAdapter.notifyDataSetChanged();
    }
}
